//
//  RHEventDetailVC.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/10/25.
//

#import "RHEventDetailVC.h"

@interface RHEventDetailVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) NSArray *dataArr;
@end

@implementation RHEventDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"Event Detail";
    self.view.backgroundColor = CFTabViewBgColor;
    [self setupUI];
}

-(void)setupUI{
    self.dataArr = @[@{CellTitle:@"Basic Information",CellContent:@[@{CellTitle:@"SN:",CellContent:@"DC01210001"},
                                                                      @{CellTitle:@"Device Name:",CellContent:@"bill device"},
                                                                      @{CellTitle:@"Adress:",CellContent:@"shen zhen"},
                                                                      @{CellTitle:@"Director:",CellContent:@"bill"},
                                                                      @{CellTitle:@"Installer:",CellContent:@"DC01210001"},
                                                                      @{CellTitle:@"Email:",CellContent:@"www.df@163.com"}]
                         
    },@{CellTitle:@"Event Information",CellContent:@[@{CellTitle:@"Des:",CellContent:@"温度过低"},
                                                        @{CellTitle:@"Source",CellContent:@"户用"},
                                                        @{CellTitle:@"Code:",CellContent:@"W1"},
                                                        @{CellTitle:@"Time:",CellContent:@"2023-10-21"}]
           
},@{CellTitle:@"Solution",CellContent:@[@{CellTitle:@"solution:",CellContent:@"XXXXXXX"}]
       
}
    ];
    
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [_tableView setBackgroundColor:CFTabViewBgColor];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setSeparatorColor:UIColor.clearColor];
    _tableView.estimatedRowHeight = 180;
    _tableView.rowHeight = UITableViewAutomaticDimension;
    _tableView.tableFooterView = [UIView new];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    
    [self.view addSubview:_tableView];
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    
    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }
    
    kWeakSelf;
    [_tableView addHeaderRefresh:^{
        
    }];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(15, 15, 0, 15));
    }];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSDictionary *dic = self.dataArr[section];
    
    return [dic[CellContent] count];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *head = [[UIView alloc]initWithFrame:CGRectMake(15, 0, kUI_WINDOW_W-30, 40)];
    head.backgroundColor = [UIColor whiteColor];
    head.layer.cornerRadius = 8;
    head.layer.masksToBounds = YES;
    head.layer.maskedCorners = kCALayerMinXMinYCorner|kCALayerMaxXMinYCorner;
    QMUILabel *titleLab = [[QMUILabel alloc]init];
    titleLab.text = self.dataArr[section][CellTitle];
    titleLab.textColor = kCOLOR_HEX(@"3F4443");
    titleLab.font = [UIFont systemFontOfSize:16];
    [head addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.centerY.mas_offset(0);
    }];
    
    UIView *line = kView;
    line.backgroundColor = kCOLOR_HEX(@"EBEDF0");
    [head addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-15);
        make.height.offset(1);
        make.bottom.mas_offset(0);
    }];
    return head;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 20;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(15, 0, kUI_WINDOW_W-30, 20)];
    footer.backgroundColor = CFTabViewBgColor;
    UIView *subView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, footer.width, 10)];
    subView.backgroundColor = [UIColor whiteColor];
    subView.layer.cornerRadius = 8;
    subView.layer.masksToBounds = YES;
    subView.layer.maskedCorners = kCALayerMinXMaxYCorner|kCALayerMaxXMaxYCorner;
    [footer addSubview:subView];
    return footer;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    cell.textLabel.text = self.dataArr[indexPath.section][CellContent][indexPath.row][CellTitle];
    cell.textLabel.font = [UIFont systemFontOfSize:14];
    cell.textLabel.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    cell.detailTextLabel.text = self.dataArr[indexPath.section][CellContent][indexPath.row][CellContent];
    cell.detailTextLabel.textColor = [UIColor colorWithHexString:@"3F4443" alpha:0.6];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
    return cell;
}



#pragma mark - JXCategoryListContentViewDelegate
/**
 实现 <JXCategoryListContentViewDelegate> 协议方法，返回该视图控制器所拥有的「视图」
 */
- (UIView *)listView {
    return self.view;
}

@end
